<?php

namespace App\Admin\Repositories;

use App\Models\TaskMemberMap as Model;
use Dcat\Admin\Repositories\EloquentRepository;
use Illuminate\Support\Facades\DB;

class TaskMemberMap extends EloquentRepository
{
    /**
     * Model.
     *
     * @var string
     */
    protected $eloquentClass = Model::class;

    public function getMemberIdListByTaskId(int $taskId) : object
    {
        return $this->eloquentClass::query()->where('task_id', $taskId)->get();
    }

    public function getTaskMapListByMemberId(array $memberIds) : object
    {
        return $this->eloquentClass::query()->whereIn('member_id', $memberIds)->get();
    }

    public function getMemberIdsFromTaskByTeams(int $status = null) : object
    {
        $query = $this->eloquentClass::query();
        if (!is_null($status)){
            $query->leftjoin('member_task', 'member_task.task_id', '=', 'task_member_map.task_id')
                ->where('member_task.status', $status);
        }
        return $query->select(DB::raw('DISTINCT(member_id)'))->get()->values();
    }
}
